import { View } from "../../../../mvc/core/View";
import { LayerManager } from "../../../manager/LayerManager";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { DataEvent } from "../../../events/DataEvent";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { InterFlowerRenderer } from "./InterFlowerRenderer";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { InterFloSimpleRenderer } from "./InterFloSimpleRenderer";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { EToplistType } from "../../../../../Message/Public/EToplistType";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { EActiveType } from "../../../../../Message/Public/EActiveType";
import { InterFloCharmReward } from "./InterFloCharmReward";
import { GTextFormat } from "../../../../common/GTextFormat";
import { TilePanel } from "../../equipment/TilePanel";
import { Global } from "../../../../../com/gengine/global/Global";
import { SoundManager } from "../../../../common/sound/SoundManager";
import { SoundTypeConst } from "../../../../common/sound/SoundTypeConst";
import { WindowLayer } from "../../../manager/WindowLayer";
import { InterFlowerRewardWindow } from "./InterFlowerRewardWindow";
import { Cache } from "../../../cache/Cache";
import { CharmRewardWindow } from "./CharmRewardWindow";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
type int = number;
//class InterFlowerWindow
    
    export  class InterFlowerWindow extends View
    {
        constructor()
        {
            super();
            this._stagerect = new Object /* flash.geom.Rectangle */();
            _layer = LayerManager.windowLayer;
            LoaderHelp.addResCallBack(ResFileConst.InterFlowerRank, this.onResLoaded);
            return;
        }

        /* internal  */onCharmActiveOpenCharmRewardHandler(arg1: DataEvent): void
        {
            this.openCharmReward();
            return;
        }

        public updateData(arg1: Array<any>): void
        {
            this._tenTilePanel.dataProvider = new DataProvider();
            this._resTilePanel.dataProvider = new DataProvider();
            if (this._firstItem) 
            {
                this._firstItem.data = null;
            }
            if (!arg1 || arg1.length <= 0) 
            {
                return;
            }
            if (this._firstItem == null) 
            {
                this._firstItem = new InterFlowerRenderer();
                this._firstItem.x = 285;
                this._firstItem.y = 40;
                addChild(this._firstItem);
            }
            this._firstItem.data = arg1[0];
            this._firstItem.resetItem();
            var loc1=arg1.length;
            if (loc1 >= 10) 
            {
                this._tenTilePanel.dataProvider = new DataProvider(arg1.slice(1, 10));
            }
            else 
            {
                this._tenTilePanel.dataProvider = new DataProvider(arg1.slice(1, loc1));
            }
            if (loc1 >= 11) 
            {
                this._resTilePanel.dataProvider = new DataProvider(arg1.slice(10, loc1));
            }
            return;
        }

        /* internal  */init(): void
        {
            this._girlFlowerBtn = ObjCreate.createGLoadedButton(ResFileConst.InterFlowerBtn, 20, 30, 153, 56, this);
            this._girlFlowerBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGirlFlowerBtnClickHandler);
            this._boyFlowerBtn = ObjCreate.createGLoadedButton(ResFileConst.InterFlowerBtn, 20, 80, 153, 56, this);
            this._boyFlowerBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBoyFlowerBtnClickHandler);
            this._btnname2 = ObjCreate.createBitmap(ImagesConst.FlowerName_1, 55, 54, this);
            this._btnName1 = ObjCreate.createBitmap(ImagesConst.FlowerName_0, 55, 104, this);
            this._closeBtn = ObjCreate.createGButton("", 780, 0, 19, 19, this, "CloseButton");
            this._closeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onCloseBtnClickHandler);
            this._tenTilePanel = this.createTilePanel(15, 152, 783, 295, 4, 3, 254, 94);
            this._tenTilePanel.rowCount = 3;
            this._tenTilePanel.setStyle("cellRenderer", InterFlowerRenderer);
            addChild(this._tenTilePanel);
            this._resTilePanel = this.createTilePanel(15, 474, 772, 85, 0, 0, 450, 28);
            this._resTilePanel.setStyle("cellRenderer", InterFloSimpleRenderer);
            addChild(this._resTilePanel);
            this._resTilePanel.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onResPanelMouseDownHandler);
            ObjCreate.createTextField(Language.getString(36170), 75, 450, 50, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(36171), 205, 450, 50, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(36172), 345, 450, 50, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(36173), 450, 450, 50, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(36174), 550, 450, 50, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(36175), 675, 450, 50, 20, this, GlobalStyle.textFormat6);
            this._isInit = true;
            var loc1=EToplistType._EToplistTypeFlowerDaily + EToplistType._EToplistTypeCrossBase;
            Dispatcher.dispatchEvent(new DataEvent(EventName.RankingTypeChange, loc1));
            return;
        }

        public setActiveType(arg1: int): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            if (arg1 != EActiveType._EActiveTypeToplistCross) 
            {
                if (arg1 == EActiveType._EActiveTypeTwoYearCrossFlowerCharm) 
                {
                    this._charmReward = new InterFloCharmReward();
                    this._charmReward.x = 570;
                    this._charmReward.y = 35;
                    this._charmReward.addEventListener(EventName.CharmActiveOpenRankReward, this.onCharmActiveOpenRankRewardHandler);
                    this._charmReward.addEventListener(EventName.CharmActiveOpenCharmReward, this.onCharmActiveOpenCharmRewardHandler);
                    addChild(this._charmReward);
                }
            }
            else 
            {
                loc1 = new GTextFormat("", 12, 15788607, null, null, null, null, null, null, null, null, null, 3);
                loc2 = Language.getString(36176);
                (loc3 = ObjCreate.createTextField(loc2, 580, 35, 195, 120, this, loc1)).wordWrap = true;
                loc3.multiline = true;
                this._lookUpRewardBtn = ObjCreate.createGButton(Language.getString(36189), 660, 108, 100, 25, this, "ButtonRed");
                this._lookUpRewardBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onLookUpRewardBtnClickHandler);
            }
            return;
        }

        /* internal  */onResLoaded(): void
        {
            this._bgA = ObjCreate.createBg(0, 0, 800, 570, this, ImagesConst.FlowerRankBgA);
            addChildAt(this._bgA, 0);
            this._upBottomBg = ObjCreate.createBitmap(ImagesConst.RankUpBottom, 8, 20, this);
            addChildAt(this._upBottomBg, 1);
            this._bgB1 = ObjCreate.createBg(8, 148, 783, 295, this, ImagesConst.FlowerRankBgB);
            this._bgB2 = ObjCreate.createBg(8, 446, 783, 115, this, ImagesConst.FlowerRankBgB);
            this._flower = ObjCreate.createBitmap(ImagesConst.Flowers, -6, -68, this);
            this._floIcon = ObjCreate.createBitmap(ImagesConst.FlowerIcon, 175, 65, this);
            this._title0 = ObjCreate.createBitmap(ImagesConst.FlowerTitle_0, 290, -50, this);
            this._title1 = ObjCreate.createBitmap(ImagesConst.FlowerTitle_1, 290, -50, this);
            this._title0.visible = false;
            this._head = ObjCreate.createBg(10, 448, 779, 26, this, ImagesConst.RankRedHead);
            this.init();
            this.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onMouseDownHandler);
            return;
        }

        /* internal  */createTilePanel(arg1: int, arg2: int, arg3: int, arg4: int, arg5: int, arg6: int, arg7: int, arg8: int): TilePanel
        {
            var loc1;
            (loc1 = new TilePanel()).move(arg1, arg2);
            loc1.setSize(arg3, arg4);
            loc1.horizontalGap = arg5;
            loc1.verticalGap = arg6;
            loc1.rowHeight = arg8;
            loc1.columnWidth = arg7;
            loc1.styleName = "ScrollBarPink";
            return loc1;
        }

        /* internal  */onBoyFlowerBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._title0.visible = true;
            this._title1.visible = false;
            var loc1=EToplistType._EToplistTypeFlowerDailyProtect + EToplistType._EToplistTypeCrossBase;
            Dispatcher.dispatchEvent(new DataEvent(EventName.RankingTypeChange, loc1));
            return;
        }

        /* internal  */onGirlFlowerBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._title0.visible = false;
            this._title1.visible = true;
            var loc1=EToplistType._EToplistTypeFlowerDaily + EToplistType._EToplistTypeCrossBase;
            Dispatcher.dispatchEvent(new DataEvent(EventName.RankingTypeChange, loc1));
            return;
        }

        /* internal  */onCloseBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Global.stage.focus = Global.stage;
            SoundManager.instance.soundPlay(SoundTypeConst.UIclose);
            hide();
            return;
        }

        /* internal  */onMouseDownHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Global.stage.addEventListener(flash.events.MouseEvent.MOUSE_UP, this.onMouseUpHandler);
            if (typeof _layer === "windowlayer") 
            {
                this._stagerect.x = 0;
                this._stagerect.y = 0;
                this._stagerect.width = this.stage.stageWidth;
                this._stagerect.height = this.stage.stageHeight;
                this.startDrag(false, this._stagerect);
            }
            else 
            {
                this.startDrag(false);
            }
            return;
        }

        /* internal  */onMouseUpHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            Global.stage.removeEventListener(flash.events.MouseEvent.MOUSE_UP, this.onMouseUpHandler);
            this.stopDrag();
            return;
        }

        /* internal  */onResPanelMouseDownHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            arg1.stopImmediatePropagation();
            return;
        }

        /* internal  */onLookUpRewardBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.openRankReward();
            return;
        }

        /* internal  */openRankReward(): void
        {
            if (this._rewardWindow == null) 
            {
                this._rewardWindow = new InterFlowerRewardWindow();
            }
            if (this._rewardWindow.isHide) 
            {
                this._rewardWindow.show(this.x + this.width - this._rewardWindow.width, this.y + 160);
            }
            else 
            {
                this._rewardWindow.hide();
            }
            if (this._charmRewardWindow && !this._charmRewardWindow.isHide) 
            {
                this._charmRewardWindow.hide();
            }
            if (Cache.instance.ranking.specialFlowerRewards == null) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.SpecialFloRewardGet));
            }
            return;
        }

        /* internal  */onCharmActiveOpenRankRewardHandler(arg1: DataEvent): void
        {
            this.openRankReward();
            return;
        }

        /* internal  */openCharmReward(): void
        {
            if (this._charmRewardWindow == null) 
            {
                this._charmRewardWindow = new CharmRewardWindow();
            }
            if (this._charmRewardWindow.isHide) 
            {
                this._charmRewardWindow.show(this.x + this.width - this._charmRewardWindow.width, this.y + 160);
                this._charmRewardWindow.updateCharmRewardList(Cache.instance.ranking.charmRewardInfo);
            }
            else 
            {
                this._charmRewardWindow.hide();
            }
            if (this._rewardWindow && !this._rewardWindow.isHide) 
            {
                this._rewardWindow.hide();
            }
            if (Cache.instance.ranking.charmRewardInfo.length == 0) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CharmActivityRewardGetConfig));
            }
            return;
        }

        public /* override */ show(arg1: int=0, arg2: int=0): void
        {
            var loc1=0;
            super.show(arg1, arg2);
            if (this._isInit) 
            {
                this._title0.visible = false;
                this._title1.visible = true;
                loc1 = EToplistType._EToplistTypeFlowerDaily + EToplistType._EToplistTypeCrossBase;
                Dispatcher.dispatchEvent(new DataEvent(EventName.RankingTypeChange, loc1));
            }
            return;
        }

        public updateReward(): void
        {
            this._rewardWindow.updateRewardList(Cache.instance.ranking.getSpecialRewardDic());
            return;
        }

        public updateCharmReward(): void
        {
            if (this._charmReward) 
            {
                this._charmReward.udpateCharmValue(Cache.instance.ranking.dailyCharm);
            }
            if (this._charmRewardWindow) 
            {
                this._charmRewardWindow.updateCharmRewardList(Cache.instance.ranking.charmRewardInfo);
            }
            return;
        }

        /* internal */ /* var */_charmReward: InterFloCharmReward;

        /* internal */ /* var */_closeBtn: GButton;

        /* internal */ /* var */_boyFlowerBtn: GLoadedButton;

        /* internal */ /* var */_girlFlowerBtn: GLoadedButton;

        /* internal */ /* var */_tenTilePanel: TilePanel;

        /* internal */ /* var */_resTilePanel: TilePanel;

        /* internal */ /* var */_rewardWindow: InterFlowerRewardWindow;

        /* internal */ /* var */_bgA: ScaleBitmap;

        /* internal */ /* var */_upBottomBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_bgB1: ScaleBitmap;

        /* internal */ /* var */_stagerect: Object /* flash.geom.Rectangle */;

        /* internal */ /* var */_bgB2: ScaleBitmap;

        /* internal */ /* var */_flower: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_floIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_btnName1: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_btnname2: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_title0: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_head: ScaleBitmap;

        /* internal */ /* var */_charmRewardWindow: CharmRewardWindow;

        /* internal */ /* var */_title1: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_firstItem: InterFlowerRenderer;

        /* internal */ /* var */_isInit: Boolean;

        /* internal */ /* var */_lookUpRewardBtn: GButton;
    }
